package com.gkj.controller;

import com.gkj.blog.business.enums.ResponseStatus;
import com.gkj.blog.business.service.TypeService;
import com.gkj.blog.business.vo.entity.TypeVo;
import com.gkj.blog.framework.object.ResponseVO;
import com.gkj.blog.util.ResultUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/type")
public class TypeController {
    @Autowired
    TypeService typeService;

    @RequestMapping("/listAll")
    public ResponseVO listAllTypes(){
        return ResultUtil.success(null,typeService.listAllType());
    }
    @RequestMapping("/add")
    public ResponseVO addType(TypeVo typeVo){
        typeService.insert(typeVo);
        return ResultUtil.success("新添类型成功--"+typeVo.getName());
    }
    @RequestMapping("/remove")
    public ResponseVO removeType(@RequestParam("ids[]") Long[] ids){
        if(ids==null){
            ResultUtil.error("至少选择一个类型");
        }
        for (Long id :
                ids) {
            typeService.delete(id);
        }
        return ResultUtil.success("成功移除"+ids.length+"个文章类型");
    }

    @RequestMapping("/get/{id}")
    public ResponseVO getType(@PathVariable("id") Long id){
        return ResultUtil.success(null,typeService.select(id));
    }

    @RequestMapping("/edit")
    public ResponseVO updata(TypeVo typeVo){
        typeService.update(typeVo);
        return ResultUtil.success("更新成功");
    }

}
